import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../config.dart';

class SettingsView extends StatefulWidget {
  const SettingsView({super.key});
  @override
  State<StatefulWidget> createState() => _SettingsViewState();
}

class _SettingsViewState extends State<SettingsView> {
  final _appid_controller = TextEditingController();
  final _secretid_controller = TextEditingController();
  final _secretkey_controller = TextEditingController();

  @override
  void initState() {
    super.initState();
    _appid_controller.text = appID.toString();
    _secretid_controller.text = secretID;
    _secretkey_controller.text = secretKey;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
            appBar: AppBar(
              title: const Text('设置'),
              leading: BackButton(onPressed: () {
                Navigator.pop(context);
              }),
            ),
            body: SingleChildScrollView(
              padding: const EdgeInsets.fromLTRB(5, 0, 5, 0),
              child: Column(
                children: [
                  Row(
                    children: [
                      const Expanded(child: Text('APPID')),
                      Expanded(
                          child: TextField(
                        controller: _appid_controller,
                        onSubmitted: (e) {
                          try {
                            appID = int.parse(e, radix: 10);
                          } catch (e) {
                            _appid_controller.text = appID.toString();
                          }
                        },
                      )),
                    ],
                  ),
                  const SizedBox(
                    height: 10,
                  ),
                  Row(
                    children: const [
                      Expanded(child: Text('SECRETID')),
                    ],
                  ),
                  Row(
                    children: [
                      Expanded(
                          child: TextField(
                        controller: _secretid_controller,
                        onSubmitted: (e) {
                          secretID = e;
                          _secretid_controller.text = e;
                        },
                      )),
                    ],
                  ),
                  const SizedBox(
                    height: 10,
                  ),
                  Row(
                    children: const [
                      Expanded(child: Text('SECRETKEY')),
                    ],
                  ),
                  Row(
                    children: [
                      Expanded(
                          child: TextField(
                        controller: _secretkey_controller,
                        onSubmitted: (e) {
                          secretKey = e;
                          _secretkey_controller.text = e;
                        },
                      )),
                      const SizedBox(width: 10)
                    ],
                  )
                ],
              ),
            )));
  }
}
